<?php

namespace Library\I18n\En;

class Date implements \Library\I18n\Date {

	public static function toHumanRelative( $time ) {
		$curr = time();
		
		if( date( 'Y', $curr ) != date( 'Y', $time ) ) {
			return date( 'Y-m-d \a\t g:sa', $time );
		}
		
		if( date( 'm', $curr ) != date( 'm', $time ) ) {
			return date( 'F j \a\t g:sa', $time );
		}
		
		if( date( 'W', $curr ) != date( 'W', $time ) ) {
			return date( 'F j \a\t g:sa', $time );
		}
		
		if( date( 'd', $curr ) != date( 'd', $time ) ) {
			$d = date( 'd', $curr ) - date( 'd', $time );
			switch( $d ) {
				case 1:
					return 'Yesterday at ' . date( 'g:sa', $time );
				default :
					return date( 'l \a\t g:sa', $time );
			}
		}
		
		$diff = $curr - $time;
		if( $diff < 10 ) {
			$time = 'a few seconds ago';
		}
		else if( $diff < 60 ) {
			$time = 'less than a minute ago';
		}
		else if ( $diff < 2 * 60 ) {
			$time = 'about a minute ago';
		}
		else if ( $diff < 50 * 60 ) {
			$time = round($diff / 60) . ' minutes ago';
		}
		else if( $diff < 90 * 60 ) {
			$time = 'about an hour ago';
		}
		else if( $diff < 24 * 60 * 60 ) {
			$time = round($diff / 3600) . ' hours ago';
		}
		else {
			$time = date( 'Y-m-d \a\t g:sa', $time );
		}
		return $time;
	}
}
